package com.lhj.jpa.future;

import java.util.concurrent.CompletableFuture;

/**
 * 其实跟thenCompose很像
 * @author linghaijin781
 * @date 2021/9/2210:20 下午
 */
public class _02_thenApply {
	public static void main(String[] args) {
		SmallTool.printTimeAndThread("小白吃好了");
		SmallTool.printTimeAndThread("小白去结账，要求开发票");

		CompletableFuture<String> cf1 = CompletableFuture.supplyAsync(() -> {
			SmallTool.printTimeAndThread("服务员收款50元");
			SmallTool.sleepMills(100);

			return "50";
		}).thenApplyAsync(money ->  {

			SmallTool.printTimeAndThread("服务员开发票, " + money + "元");
			SmallTool.sleepMills(200);
			return money+"元发票";
		});

		SmallTool.printTimeAndThread("小白接了个电话");
		SmallTool.printTimeAndThread(String.format("%s 到手, 小白回家", cf1.join()));
	}
}
